/**
 *******************************************************************************
 * @FileName  : defs_types.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef DEFS_TYPES_H_
#define DEFS_TYPES_H_

#include "libc/complier.h"
#include "libc/types.h"
#include "libc/string.h"

#define UNUSED(x)   (void)(x)

#define OFFSET_OF(type, field)   ((uint32_t) &((type *)0)->field)

/**
 * Usage:
 * typedef struct scm2010_ipc_frame_s
 * {
 *    FAR scm2010_ipc_payload_t *payload;
 *    bool                            tx;
 *    bool                        in_use;
 *    bool                       reclaim;
 *    dq_entry_t              list_entry;
 * } scm2010_ipc_frame_t;
 *
 *  dq_entry_t *list = dq_peek(&ipc->rx_queue);
 *  scm2010_ipc_frame_t *tmp = container_of(list, scm2010_ipc_frame_t, list_entry);
 *
 */
#define CONTAINER_OF(ptr, type, field) (type *) ( (uint8_t *)ptr - OFFSET_OF(type, field) )


#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...)    _n
#define COUNT_ARGS(X...)  __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

#endif /* DEFS_TYPES_H_ */
